package com.ymx.darling.wrapper.fragment;

import com.ymx.darling.bean.sql.BoundSql;
import com.ymx.darling.bean.sql.SqlParsingHelper;
import com.ymx.darling.wrapper.fragment.lambda.WhereLambda;
import com.ymx.darling.bean.sql.SqlStatement;

import java.util.ArrayList;

public class HavingSegment implements SqlSegment {
    private SqlStatement havingStatement = new SqlStatement("", new ArrayList<>());

    @Override
    public SqlStatement getSqlStatement(){
        return this.havingStatement;
    }

    public void splitHaving(WhereLambda whereLambda){
        WhereSegment whereSplit = whereLambda.subWhere(new WhereSegment());
        this.havingStatement = whereSplit.getSqlStatement();
    }

    public void splitHaving(String havingSql, Object... param) {
        BoundSql boundSql = SqlParsingHelper.parseSqlTemplate(havingSql, param);
        boundSql.bindSqlParameter();
        this.havingStatement = new SqlStatement(boundSql.getSql(), boundSql.getBindParameters());
    }
}
